
s = '13+2/2+4*2-2'

def chaifen(s):
    """拆分"""
    nums = []
    ops = []
    index = 0
    for i in range(len(s)):
        if s[i] in '+-*/':
            ops.append(s[i])
            nums.append(int(s[index:i]))
            index = i+1
        if i + 1 == len(s):
            nums.append(int(s[index:i+1]))
    return nums, ops

def run(num1, num2, op):
    if op == "+":
        return num1+num2
    elif op == '-':
        return num1-num2
    elif op == "*":
        return num1*num2
    elif op == '/':
        return num1/num2

def opration(nums, ops, match):
    i = 0
    while i<len(ops):
        if ops[i] in match:
            nums[i] = run(nums[i],nums[i+1], ops[i])
            del nums[i+1]
            del ops[i]
        else:
            i+=1
    return nums, ops


nums, ops = chaifen(s)
print(nums, ops)
nums, ops = opration(nums, ops, '*/')
print(nums, ops)
nums, ops = opration(nums, ops, "+-")
print(nums, ops)
print(f"最终的结果是{nums[0]}")




